package 一五省;

import java.util.Scanner;
import java.util.Vector;

public class q9 {

	public static int num = 0;
	
	//每个骰子不同的组合方式
	public static String[] saizi = {"14","41","25","52","36","63"};
	
	//骰子的数量
	public static int total = 0;
	
	//不稳定的组合
	public static String[] inreablie;
	
	/**
	 * 判断是否稳定
	 * @param str
	 * @param imposblie
	 * @return
	 */
	public static boolean jodge(String str,String[] imposblie){
		for(int i=0;i<imposblie.length;i++){
			if(str.indexOf(imposblie[i])!=-1 || str.indexOf(reverse(imposblie[i]))!=-1){
				return false;
			}
		}
		return true;
	}
	
	
	/**
	 * 计算符合条件的(递归的方法)
	 * @param result
	 */
	public static void getResult(Vector<String> result){
		if(result.size() == total){
			String str = "";
			for(int i=0;i<result.size();i++){
				str+=result.elementAt(i);
			}
			if(jodge(str,inreablie)){
				num++;
			}
			return;
		}
		
		for(int i=0;i<saizi.length;i++){
			Vector<String> tresult = new Vector<String>(result);
			tresult.add(saizi[i]);
			getResult(tresult);
		}
	}
	
	
	/**
	 * 翻转字符串
	 * @param str
	 * @return
	 */
	public static String reverse(String str){
		return new StringBuffer(str).reverse().toString();
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scanner = new Scanner(System.in);
		total = scanner.nextInt();
		int m = scanner.nextInt();
		inreablie = new String[m];
		int i=0;
		String[] str;
		scanner.nextLine();
		
		while(m-->0){
			str = scanner.nextLine().split(" ");
			inreablie[i++] = str[0] + str[1];
		}
		
		Vector<String> result = new Vector<String>();
		getResult(result);
		
		System.out.println((int)(num*Math.pow(4, (double)total)%(Math.pow(10, 9) + 7)));
	}
	
	

}
